﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.Graphics.Shaders;

namespace Terraria.Graphics.Effects
{
	// Token: 0x020003A0 RID: 928
	public class SimpleOverlay : Overlay
	{
		// Token: 0x06002091 RID: 8337 RVA: 0x00016E65 File Offset: 0x00015065
		public SimpleOverlay(string textureName, ScreenShaderData shader, EffectPriority priority = EffectPriority.VeryLow, RenderLayers layer = RenderLayers.All) : base(priority, layer)
		{
			this._texture = TextureManager.AsyncLoad((textureName == null) ? "" : textureName);
			this._shader = shader;
		}

		// Token: 0x06002092 RID: 8338 RVA: 0x00016E98 File Offset: 0x00015098
		public SimpleOverlay(string textureName, string shaderName = "Default", EffectPriority priority = EffectPriority.VeryLow, RenderLayers layer = RenderLayers.All) : base(priority, layer)
		{
			this._texture = TextureManager.AsyncLoad((textureName == null) ? "" : textureName);
			this._shader = new ScreenShaderData(Main.ScreenShaderRef, shaderName);
		}

		// Token: 0x06002093 RID: 8339 RVA: 0x00016ED5 File Offset: 0x000150D5
		public ScreenShaderData GetShader()
		{
			return this._shader;
		}

		// Token: 0x06002094 RID: 8340 RVA: 0x0045CBA8 File Offset: 0x0045ADA8
		public override void Draw(SpriteBatch spriteBatch)
		{
			this._shader.UseGlobalOpacity(this.Opacity);
			this._shader.UseTargetPosition(this.TargetPosition);
			this._shader.Apply();
			spriteBatch.Draw(this._texture.Value, new Rectangle(0, 0, Main.screenWidth, Main.screenHeight), Main.bgColor);
		}

		// Token: 0x06002095 RID: 8341 RVA: 0x00016EDD File Offset: 0x000150DD
		public override void Update(GameTime gameTime)
		{
			this._shader.Update(gameTime);
		}

		// Token: 0x06002096 RID: 8342 RVA: 0x00016EEB File Offset: 0x000150EB
		public override void Activate(Vector2 position, params object[] args)
		{
			this.TargetPosition = position;
			this.Mode = OverlayMode.FadeIn;
		}

		// Token: 0x06002097 RID: 8343 RVA: 0x00016EFB File Offset: 0x000150FB
		public override void Deactivate(params object[] args)
		{
			this.Mode = OverlayMode.FadeOut;
		}

		// Token: 0x06002098 RID: 8344 RVA: 0x00016F04 File Offset: 0x00015104
		public override bool IsVisible()
		{
			return this._shader.CombinedOpacity > 0f;
		}

		// Token: 0x04003D28 RID: 15656
		private Ref<Texture2D> _texture;

		// Token: 0x04003D29 RID: 15657
		private ScreenShaderData _shader;

		// Token: 0x04003D2A RID: 15658
		public Vector2 TargetPosition = Vector2.Zero;
	}
}
